from rest_framework import serializers

from meiduo_admin.mypakge import *
from orders.models import OrderInfo
from goods.models import SKU


# order——订单详情模型类序列化器中的skus字段中的sku字段
class order___SKUSerializer(serializers.ModelSerializer):
    class Meta:
        model = SKU
        fields = [
            'name',
            'default_image'    # 图片字段填写错误导致没有现象default_image
        ]


# order—— 订单详情模型类序列化器中的skus字段进行序列化
class order___OrderGoodsSerializer(serializers.ModelSerializer):
    sku = order___SKUSerializer()
    class Meta:
        model = OrderGoods
        fields = [
            'count',
            'price',
            'sku'
        ]

# order——订单详情模型类序列化器
class order___OrderDetailModelSerializer(serializers.ModelSerializer):
    user = serializers.StringRelatedField
    skus = order___OrderGoodsSerializer(many=True)
    class Meta:
        model = OrderInfo
        fields = "__all__"
# order_订单展示模型类序列化器
class order___OrderModelSerializer(serializers.ModelSerializer):
    # class Meta:
    #     model = OrderInfo
    #     fields = '__all__'
    class Meta:
        model = OrderInfo
        fields = [
            'order_id',
            'create_time'
        ]

        extra_kwargs = {
            "create_time": {"format": "%Y/%m/%d"}
        }









